<template>
  <el-form class="el-form-left" label-position="left" :model="formData" :inline="true" label-suffix="：">
    <el-form-item :label="$getTextByLangKey('产线')">
      <el-select v-model="formData.lineName" placeholder="请选择" style="width: 100px;">
        <el-option
          v-for="item in lineList"
          :key="item.id"
          :label="item.lineName"
          :value="item.lineName"
        >
        </el-option>
      </el-select>
    </el-form-item>
    <el-form-item :label="$getTextByLangKey('工单')">
      <el-input v-model="formData.orderNo" style="width: 100px;"></el-input>
    </el-form-item>
    <el-form-item :label="$getTextByLangKey('PCBA编号')">
      <el-input v-model="formData.pcbaCode" style="width: 100px;"></el-input>
    </el-form-item>
    <el-form-item :label="$getTextByLangKey('生产起始时间')">
      <el-date-picker v-model="formData.createTimeStart" style="width: 173px;"
                      type="datetime" placeholder="选择日期">
      </el-date-picker>
    </el-form-item>
    <el-form-item :label="$getTextByLangKey('生产结束时间')">
      <el-date-picker v-model="formData.createTimeEnd" style="width: 173px;"
                      type="datetime" placeholder="选择日期">
      </el-date-picker>
    </el-form-item>
    <el-form-item >
      <el-button type="primary" @click="handleSearch">{{$getTextByLangKey('查询')}}</el-button>
      <el-button style="margin-left: 4px" @click="handleClearSearch">{{$getTextByLangKey('清空')}}</el-button>
      <el-button style="margin-left: 4px" @click="handleExport">{{$getTextByLangKey('导出')}}</el-button>
      <el-button style="margin-left: 4px" @click="handleBomExport">{{$getTextByLangKey('物料导出')}}</el-button>
    </el-form-item>

  </el-form>
</template>
<script>

  import request from '@/common/js/request'

  export default {
    name: "pcba-record-filter",
    data() {
      return {
       formData: {
       },
        lineList:[]
      }
    },
    created: function () {
      request.requestLineList(res=>{
        this.lineList = res.data.data
      })
    },
    methods: {
      handleClearSearch(){
        this.formData.pcbaCode = ''
        this.formData.orderNo = ''
        this.formData.lineName = ''
        this.formData.createTimeEnd = ''
        this.formData.createTimeStart = ''
        this.handleSearch()
      },
      // 转换时间格式的formData
      getNewFormData(){
        const newFormData = {...this.formData}
        if(newFormData.createTimeEnd){
          newFormData.createTimeEnd = new Date(newFormData.createTimeEnd).getTime()
        }
        if(newFormData.createTimeStart){
          newFormData.createTimeStart = new Date(newFormData.createTimeStart).getTime()
        }
        return newFormData
      },
      handleSearch(){

        const newFormData = this.getNewFormData()
        this.$emit('search',newFormData)
      },
      handleExport(){
        const newFormData = this.getNewFormData()
        this.$emit('exportExcel',newFormData)
      },
      handleBomExport(){
        const newFormData = this.getNewFormData()
        this.$emit('exportBomExcel',newFormData)
      }
    }
  }

</script>

<style scoped>

  .el-form-left{
    padding: 10px;
  }

</style>
